/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.sun.ShipperProcessor;

import com.sun.Entity.Productinfo;
import com.sun.Entity.Shippingorder;
import com.sun.Facade.ProductinfoFacadeLocal;
import com.sun.Facade.ShippingorderFacadeLocal;
import javax.ejb.EJB;
import javax.jws.WebMethod;
import javax.jws.WebParam;
import javax.jws.WebService;
import javax.ejb.Stateless;

/**
 *
 * @author test
 */
@WebService()
@Stateless()
public class EstimateOrderAmountWS {

    @EJB
    private ProductinfoFacadeLocal productinfoFacade;
    @EJB
    private ShippingorderFacadeLocal shippingorderFacade;

    /**
     * Web service operation
     */
    @WebMethod(operationName = "EstimateOrderAmount")
    public Float EstimateOrderAmount(@WebParam(name = "OrderID") String OrderID) {

        // Get Amount for 1 product
        Shippingorder order = shippingorderFacade.find(OrderID);
        String ProductTypeId = order.getProducttypeid();
        Productinfo prod = productinfoFacade.find(ProductTypeId);
        float ShipCosts = prod.getManufacturingcost();
        Integer Quantity = order.getProductquantity();

        // calculate order amount (multiplication)
        Float Amount = new Float(ShipCosts * Quantity);

        // update the order line db
        order.setAmount(Amount);
        shippingorderFacade.edit(order);

        return Amount;
    }
}
